package com.api.shopapi.mapper;

import com.api.shopapi.entity.CheckinSetmeal;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author maochuan
 */
@Repository
@Mapper
public interface CheckinSetmealMapper {
    @Insert("insert into checkin_setmeal " +
            "(CheckinSetmealCode,Name,NursingLevelCode,NursingLevelName,NursingLevelPrice,RoomTypeCode,RoomTypePrice,Status,CreateTime,StaffCode,InstitutionCode,Univalence) " +
            "value(#{checkinSetmeal.CheckinSetmealCode},#{checkinSetmeal.Name}," +
            "#{checkinSetmeal.NursingLevelCode},#{checkinSetmeal.NursingLevelName},#{checkinSetmeal.NursingLevelPrice},#{checkinSetmeal.RoomTypeCode},#{checkinSetmeal.RoomTypePrice}," +
            "#{checkinSetmeal.Status},#{checkinSetmeal.CreateTime},#{checkinSetmeal.StaffCode},#{checkinSetmeal.InstitutionCode},#{checkinSetmeal.Univalence})")
    int insert(@Param("checkinSetmeal") CheckinSetmeal checkinSetmeal);

    @Update("update checkin_setmeal set Name = #{checkinSetmeal.Name},NursingLevelCode=#{checkinSetmeal.NursingLevelCode}," +
            "NursingLevelName=#{checkinSetmeal.NursingLevelName},NursingLevelPrice=#{checkinSetmeal.NursingLevelPrice},RoomTypeCode=#{checkinSetmeal.RoomTypeCode},RoomTypePrice=#{checkinSetmeal.RoomTypePrice},Status=#{checkinSetmeal.Status}," +
            "CreateTime=#{checkinSetmeal.CreateTime},StaffCode=#{checkinSetmeal.StaffCode},InstitutionCode=#{checkinSetmeal.InstitutionCode},Univalence=#{checkinSetmeal.Univalence} " +
            "where CheckinSetmealCode=#{checkinSetmeal.CheckinSetmealCode}")
    int updateByCheckinSetmealCode(@Param("checkinSetmeal") CheckinSetmeal checkinSetmeal);

    @Select("select * from checkin_setmeal where InstitutionCode=#{institutionCode} and Status=0 order by CreateTime desc")
    List<CheckinSetmeal> getListAll(@Param("institutionCode") String institutionCode);

    @Select("select * from checkin_setmeal where CheckinSetmealCode=#{checkinSetmealCode} limit 1")
    CheckinSetmeal getByCheckinSetmealCode(@Param("checkinSetmealCode") String checkinSetmealCode);

    @Select("select * from checkin_setmeal where InstitutionCode=#{institutionCode} and Name=#{name} limit 1")
    CheckinSetmeal getByInstitutionCodeAndName(@Param("institutionCode") String institutionCode, @Param("name") String name);

    @Select("select * from checkin_setmeal where InstitutionCode=#{institutionCode} order by CreateTime desc")
    List<CheckinSetmeal> getListByInstitutionCode(@Param("institutionCode")String institutionCode);


    @Select("select * from checkin_setmeal" +
            " where" +
            " institutionCode in (select institutionCode from institution where governmentCode=#{governmentCode})"+
            " order by CreateTime desc")
    List<CheckinSetmeal> listByGovCode(@Param("governmentCode")String governmentCode);


}
